import Mock from 'mockjs'


// const data1 = Mock.mock({
// 	'string|1-3': '你好！ '
// })

// const data2 = Mock.mock({
// 	'string|1-10': '@cword()'
// })

// const data3 = Mock.mock({
// 	'string': '@cword(10)'
// })

// console.log(data1)
// console.log(data2)
// console.log(data3)


// const data4 = Mock.mock({
// 	'string': '@csentence()'
// })

// console.log(data4) // "报示片在速象采白一去人于些去记查近。" 


// const data5 = Mock.mock({
// 		'paragragh': '@cparagraph(5)'
// 	})
	
// console.log(data5.paragragh) // 

// const data6 = Mock.mock({
// 		'number|1-100': 10
// 	})
	
// console.log(data6) // "报示片在速象采白一去人于些去记查近。" 




// const data7 = Mock.mock({
// 		id: '@id()',
// 		address: '@city(true)'
// 	})
	
// console.log(data7) // "340000199903104484" 



// const data8 = Mock.mock({
// 		date: '@date(yyyy-MM-dd hh-mm-ss)'
// 	})
	
// console.log(data8) // "340000199903104484" 



// 先定义数据
const { userlist } = Mock.mock({
	'userlist|5-20' :[
		{
			name: '@cname()',
			address: '@city(true)',
			id:'@id()'
		}
	]
})

// 拦截请求

// 获取操作  ‘查’
Mock.mock('/api/users','get', ()=>{
	return {
		users: userlist
	}
	
})

//  增加
Mock.mock('/api/add/users','post', (option)=>{
	const body = JSON.parse(option.body)
	userlist.push(Mock.mock(
		{
			name: body.name,
			address: body.address,
			id:'@id()'
		}
	)	
	)
	return {
		status:200,
		message:'添加成功',
		users: userlist
	}
	
})

//    删除
Mock.mock('/api/remove/users', 'post', (option)=>{
	const body = JSON.parse(option.body)
	const index =	userlist.findIndex(item=>{
		return item.id === body.val
	})
	userlist.splice(index,1)
	return {
		status:200,
		message:'删除成功',
		users: userlist
	}
	
})